$(function() {
	$('.link').popup({
	    position:'bottom center'
	  })
	;
	//星星不可点击
	$('div.ui.massive.star.rating.grade').rating('disable');
	//爱心。等级高于5的学生
	$('div.ui.heart.rating').rating('disable');
	//鼠标悬停效果
	$('.special.cards .image').dimmer({
		  on: 'hover'
		});
	//修改客户等级
	$('div[id^="changeGrade"]').on('click',function(){
		$('div.ui.modal.grade')
		  .modal('show')
		;
//		//改变星星可点
//		$('div.ui.modal.grade')
//		  .on('click',function(){})
//		;
		//改变星星个数
		$('div.ui.massive.star.rating.change')
		  .rating('enable')
		;
	});
	
	
	//改变用户等级
	$('#changeRating').on('click',function(){
		var gradeName=['完全没兴趣','可发展客户','潜在客户','意向客户'];
		var ratingNums = $('div.ui.massive.star.rating.change')
		  .rating('get').rating();
		var $gradeId= $('#gradeId');
		var $gradeName=$('#gradeName');
		$gradeId.attr('value',$('div.ui.massive.star.rating.change')
				  .rating('get').rating());
		$gradeName.text(gradeName[ratingNums-1]);
	});
	
	//筛选时，双击取消，和传递参数
	var tiemfun = null;
	$('#btn1').on('click',function(){
		if(!$('#want1').length){
			$('#selected').append('<input class="ui teal button" type="button"  id="want1"  value="意向客户">')
			$('#selected').append('<input type="hidden" name="class" id="input_btn1" value="4">')
			$('#want1').bind('click',function(){
				clearTimeout(tiemfun);
				tiemfun=setTimeout(function(){
				}, 300);
			}).bind('dblclick',function(){
				clearTimeout(tiemfun);
				$('#want1').remove();
				$('#input_btn1').remove();
			});
		}
	});
	
	$('#btn2').on('click',function(){
		if(!$('#want2').length){
			$('#selected').append('<input class="ui teal button" type="button"  id="want2" value="潜在客户">')
			$('#selected').append('<input type="hidden" name="class" id="input_btn2" value="3">')
			$('#want2').bind('click',function(){
				clearTimeout(tiemfun);
				tiemfun=setTimeout(function(){
				}, 300);
			}).bind('dblclick',function(){
				clearTimeout(tiemfun);
				$('#want2').remove();
				$('#input_btn2').remove();
			});
		}
	});
	
	$('#btn3').on('click',function(){
		if(!$('#want3').length){
			$('#selected').append('<input class="ui teal button" type="button"  id="want3" value="可发展客户">')
			$('#selected').append('<input type="hidden" name="class" id="input_btn3" value="2">')
			$('#want3').bind('click',function(){
				clearTimeout(tiemfun);
				tiemfun=setTimeout(function(){
				}, 300);
			}).bind('dblclick',function(){
				clearTimeout(tiemfun);
				$('#want3').remove();
				$('#input_btn3').remove();
			});
		}
	});
	
	$('#btn4').on('click',function(){
		if(!$('#want4').length){
			$('#selected').append('<input class="ui teal button" type="button"  id="want4" value="完全没兴趣">')
			$('#selected').append('<input type="hidden" name="class" id="input_btn4" value="1">')
			$('#want4').bind('click',function(){
				clearTimeout(tiemfun);
				tiemfun=setTimeout(function(){
				}, 300);
			}).bind('dblclick',function(){
				clearTimeout(tiemfun);
				$('#want4').remove();
				$('#input_btn4').remove();
			});
		}
	});
	//点击取消按钮之后去除div区域的input元素
	$('#mycancel').on('click',function(){
		var div = document.getElementById('selected');
		var input = div.getElementsByTagName('input');
		if(input.length){
			for (var i = 0; i < input.length; i++) {
				input[i].remove();
			}
		}
	});
	//复选框删除
		$("div.checkbox").checkbox();
		var checkAll = $("#checkAll");
		var itemCheck = $(".item-check");

		checkAll.on("change", function() {
			//获取全选框选中状态
			itemCheck.prop("checked", this.checked)
		});

		itemCheck.on("change", function() {
			//判断判断选中的个数是否和所有存在个数一样
			var checkeds = $(".item-check:checked");
			//修改checkAll的checked属性
			checkAll.prop("checked", checkeds.length == itemCheck.length);
		});
		$('#delete').on('click', function() {
			//获取所有选中
			var checkeds = $(".item-check:checked");
			if (checkeds.length && confirm("确认要删除所有选中行吗？")) {
				//获取所有选择的id
				var ids = [];
				checkeds.each(function() {
					ids.push(this.value);
				});
				location.replace("counselor/delete?id=" + ids.join("&id="));
			}
		});

	});

function dow(){
	$('.ui.labeled.icon.sidebar')
		.sidebar('setting', 'transition','overlay')
		.sidebar('toggle');
}

function select() {
	$('.ui.modal')
	  .modal('show');
}
function logout(){
	var isLog = confirm("你确定要注销吗？");
	if(isLog){
		location.replace("logout.jsp");
	}
}

//附件上传
$(function() {
	//$('#fileupload')匹配的元素必须是file选择框
	$('#fileupload').fileupload({
		url : "upload",
		dataType : 'json',
		formData:[{
			name:"model",
			value:"follow_up"
		}],
		done : function(e, data) {
			//上传结果返回后，判断是否成功
			if(data.result.message){
				alert(data.result.message);
			}else{
				var p = $('<p/>');
				p.append("<input type='hidden' name='attachs' value='"+data.result.id+"'>");
				p.append("<span>"+data.result.fileName+"</span>");
				p.append("<a class='delete-file'>删除</a>");
				p.appendTo('.files');
			}
			$(".fileinput-text").text("选择文件");
		},
		progressall : function(e, data) {
			var progress = parseInt(data.loaded / data.total * 100, 10);
			$(".fileinput-text").text("上传中..."+progress + '%');
		},
		start:function(){
			$(".fileinput-text").text("上传中...");
		}
	});
	
	$(".files").on("click", ".delete-file", function(){
		$(this).parent().remove();
	});
	
});

//修改跟进记录
function change(stuId, recordId) {
	$('.modal.record').modal('show');
	var $stuId = $('#stuId');
	var $recordId = $('#recordId');
	$recordId.attr('value', recordId);
	$stuId.attr('value', stuId);
}
